﻿using System;
using System.Linq;
using CodeCounsel.SharePoint.RibbonDesigner.Model;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace CodeCounsel.SharePoint.RibbonDesigner.ViewModel
{
    public class TabViewModelCollection
        : ObservableCollection<TabViewModel>
    {
        TabContainer _tabs;
        RibbonTemplates _templates;

        public TabViewModelCollection(
            TabContainer tabs, RibbonTemplates templates)
        {
            _tabs = tabs;
            _templates = templates;
            LoadTabs();
        }

        void LoadTabs()
        {
            ClearItems();
            foreach (TabViewModel tab in ExtensionManager.GetReplacedChildren<Tab>(_tabs)
                .Select(tab => new TabViewModel(
                    (Tab)tab,
                    _templates)))
            {
                Add(tab);
            }
        }
    }
}
